﻿namespace Chain.BLL
{
    using Chain.DAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class MemRecharge
    {
        private readonly Chain.DAL.MemRecharge dal = new Chain.DAL.MemRecharge();

        public int Add(Chain.Model.MemRecharge model)
        {
            return this.dal.Add(model);
        }

        public DataTable AgainPrint(int rechargeID)
        {
            return this.dal.AgainPrint(rechargeID);
        }

        public List<Chain.Model.MemRecharge> DataTableToList(DataTable dt)
        {
            List<Chain.Model.MemRecharge> list = new List<Chain.Model.MemRecharge>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.MemRecharge item = new Chain.Model.MemRecharge();
                    if ((dt.Rows[i]["RechargeID"] != null) && (dt.Rows[i]["RechargeID"].ToString() != ""))
                    {
                        item.RechargeID = int.Parse(dt.Rows[i]["RechargeID"].ToString());
                    }
                    if ((dt.Rows[i]["RechargeMemID"] != null) && (dt.Rows[i]["RechargeMemID"].ToString() != ""))
                    {
                        item.RechargeMemID = int.Parse(dt.Rows[i]["RechargeMemID"].ToString());
                    }
                    if ((dt.Rows[i]["RechargeAccount"] != null) && (dt.Rows[i]["RechargeAccount"].ToString() != ""))
                    {
                        item.RechargeAccount = dt.Rows[i]["RechargeAccount"].ToString();
                    }
                    if ((dt.Rows[i]["RechargeType"] != null) && (dt.Rows[i]["RechargeType"].ToString() != ""))
                    {
                        item.RechargeType = int.Parse(dt.Rows[i]["RechargeType"].ToString());
                    }
                    if ((dt.Rows[i]["RechargeMoney"] != null) && (dt.Rows[i]["RechargeMoney"].ToString() != ""))
                    {
                        item.RechargeMoney = decimal.Parse(dt.Rows[i]["RechargeMoney"].ToString());
                    }
                    if ((dt.Rows[i]["RechargeRemark"] != null) && (dt.Rows[i]["RechargeRemark"].ToString() != ""))
                    {
                        item.RechargeRemark = dt.Rows[i]["RechargeRemark"].ToString();
                    }
                    if ((dt.Rows[i]["RechargeShopID"] != null) && (dt.Rows[i]["RechargeShopID"].ToString() != ""))
                    {
                        item.RechargeShopID = int.Parse(dt.Rows[i]["RechargeShopID"].ToString());
                    }
                    if ((dt.Rows[i]["RechargeCreateTime"] != null) && (dt.Rows[i]["RechargeCreateTime"].ToString() != ""))
                    {
                        item.RechargeCreateTime = DateTime.Parse(dt.Rows[i]["RechargeCreateTime"].ToString());
                    }
                    if ((dt.Rows[i]["RechargeUserID"] != null) && (dt.Rows[i]["RechargeUserID"].ToString() != ""))
                    {
                        item.RechargeUserID = int.Parse(dt.Rows[i]["RechargeUserID"].ToString());
                    }
                    if ((dt.Rows[i]["RechargeCardBalance"] != null) && (dt.Rows[i]["RechargeCardBalance"].ToString() != ""))
                    {
                        item.RechargeCardBalance = decimal.Parse(dt.Rows[i]["RechargeCardBalance"].ToString());
                    }
                    if ((dt.Rows[i]["RechargeIsApprove"] != null) && (dt.Rows[i]["RechargeIsApprove"].ToString() != ""))
                    {
                        if ((dt.Rows[i]["RechargeIsApprove"].ToString() == "1") || (dt.Rows[i]["RechargeIsApprove"].ToString().ToLower() == "true"))
                        {
                            item.RechargeIsApprove = true;
                        }
                        else
                        {
                            item.RechargeIsApprove = false;
                        }
                    }
                    if ((dt.Rows[i]["RechargePoint"] != null) && (dt.Rows[i]["RechargePoint"].ToString() != ""))
                    {
                        item.RechargePoint = int.Parse(dt.Rows[i]["RechargePoint"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int RechargeID)
        {
            return this.dal.Delete(RechargeID);
        }

        public bool DeleteList(string RechargeIDlist)
        {
            return this.dal.DeleteList(RechargeIDlist);
        }

        public bool Exists(int RechargeID)
        {
            return this.dal.Exists(RechargeID);
        }

        public bool Exists(string orderaccount)
        {
            return this.dal.Exists(orderaccount);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public decimal GetGiveMoney(string strWhere)
        {
            return this.dal.GetGiveMoney(strWhere);
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public DataSet GetListSP1(int PageSize, int PageIndex, string IndexColumn, bool isAsc, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP1(PageSize, PageIndex, IndexColumn, isAsc, out resCount, strWhere);
        }

        public DataSet GetListSP2(int PageSize, int PageIndex, string IndexColumn, bool isAsc, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP2(PageSize, PageIndex, IndexColumn, isAsc, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.MemRecharge GetModel(int RechargeID)
        {
            return this.dal.GetModel(RechargeID);
        }

        public List<Chain.Model.MemRecharge> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public DataSet GetRechargeByTime(DateTime starttime, DateTime endtime, string strwhere)
        {
            return this.dal.GetRechargeByTime(starttime, endtime, strwhere);
        }

        public decimal GetRechargeMoney(string strWhere)
        {
            return this.dal.GetRechargeMoney(strWhere);
        }

        public decimal GetRecMoney(string strWhere)
        {
            return this.dal.GetRecMoney(strWhere);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.MemRecharge model)
        {
            return this.dal.Update(model);
        }

        public int UpdateRecharge(int rechargeID)
        {
            return this.dal.UpdateRecharge(rechargeID);
        }
    }
}

